# 封装：
#
# 家具类：HouseItem
# 属性：名字(name)、占地面积(area)
# 方法：__str__
#
# 房屋类：House
# 属性：户型(type)、总面积(total_area)、剩余面积(free_area)、家具名称列表(item_list)
# 方法：添加家具(add_item)、__str__
# class House(object):
#     def __init__(self, type, total_area):
#         self.type = type
#         self.totala_area = total_area
#         self.free_area = total_area
#         self.item_list = []
#
#     def __str__(self):
#         return (f"户型:{self.type},总面积：{self.totala_area},"
#                 f"剩余面积:{self.free_area},家具名称列表{self.item_list}")
#
#     def add_items(self, house_item):
#         if self.free_area >= house_item.area:
#             self.free_area -= house_item.area
#             self.item_list.append(house_item.name)
#
#         else:
#             print("面积不够，请换大房子")
#
#
# class HouseItem(object):
#     def __init__(self, name, area):
#         self.name = name
#         self.area = area
#
#     def __str__(self):
#         return f"{self.name}占地面积是{self.area}平米"
#
#
# bed = HouseItem("席梦思", 4)
# chest = HouseItem("衣柜", 2)
# table = HouseItem("餐桌", 1.5)
#
# print(bed)
# print(chest)
# print(table)
#
# house = House("大别野", 20)
# print(house)
#
# house.add_items(bed)
# print(house)
#
# house.add_items(chest)
# print(house)
#
# house.add_items(table)
# print(house)


# 封装：
#
# 家具类：HouseItem
# 属性：名字(name)、占地面积(area)
# 方法：__str__
#
# 房屋类：House
# 属性：户型(type)、总面积(total_area)、剩余面积(free_area)、家具名称列表(item_list)
# 方法：添加家具(add_item)、__str__

class House(object):
    def __init__(self, type, total_area):
        self.type = type
        self.total_area = total_area
        self.free_area = total_area
        self.item_list = []

    def __str__(self):
        return (f"户型:{self.type},总面积:{self.total_area},"
                f"剩余面积:{self.free_area},家具名称列表:{self.item_list}")

    def add_items(self, house_item):
        if self.free_area >= house_item.area:
            self.free_area -= house_item.area
            self.item_list.append(house_item.name)

        else:
            print("面积不够，再买个大的")


class HouseItem(object):
    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return f"{self.name},占地{self.area}平方"


bed = HouseItem("席梦思", 4)
chest = HouseItem("衣柜", 2)
table = HouseItem("餐桌", 1.5)
print(bed)
print(chest)
print(table)

house = House("大别野", 20)
print(house)

house.add_items(bed)
print(house)
house.add_items(chest)
print(house)
house.add_items(table)
print(house)
